<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增笔记</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="../static/editor/css/editormd.css"/>

    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script src="../static/editor/editormd.js"></script>



    <script type="text/javascript">
        var myEditor = null;
        $(function() {
            myEditor = editormd("nodeContent", {
                width: "100%",
                height: 640,
                markdown : "",
                path : 'static/editor/lib/',
                //dialogLockScreen : false,   // 设置弹出层对话框不锁屏，全局通用，默认为 true
                //dialogShowMask : false,     // 设置弹出层对话框显示透明遮罩层，全局通用，默认为 true
                //dialogDraggable : false,    // 设置弹出层对话框不可拖动，全局通用，默认为 true
                //dialogMaskOpacity : 0.4,    // 设置透明遮罩层的透明度，全局通用，默认值为 0.1
                //dialogMaskBgColor : "#000", // 设置透明遮罩层的背景颜色，全局通用，默认为 #fff
                imageUpload : true,
                imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                imageUploadURL : "/upload",
                saveHTMLToTextarea: true

                /*
                 上传的后台只需要返回一个 JSON 数据，结构如下：
                 {
                    success : 0 | 1,           // 0 表示上传失败，1 表示上传成功
                    message : "提示的信息，上传成功或上传失败及错误信息等。",
                    url     : "图片地址"        // 上传成功时才返回
                 }
                 */
            });
        });

        function subNode(){
            var title = $("#nodeTitle").val();
            var content = myEditor.getHTML();

            if(title == ""){
                alert("题目不得为空！");
                return;
            }

            if(content == ""){
                alert("正文不得为空！");
                return;
            }

            $.post("addNode",{
                nodeTitle : title,
                nodeContent : content
            },function (data,status) {
                if(status != "success"){
                    alert("服务器出现异常，请稍后重试！");
                    return;
                }
                if(data == "ok"){
                    alert("新增成功！");
                    window.location.href = "main.html";
                    return;
                }
                if(data == "fail"){
                    alert("新增失败！");
                    return;
                }
                alert(data);
            });
        }

        $(function () {
            $.post("selectUserName",function (data,status) {
                if(status != "success"){
                    alert("服务出现问题，请稍后再试！");
                    return;
                }
                if(data == "failLogin"){
                    alert("请先进行登录！！")
                    window.location.href="index.html";
                    return;
                }
                $("#userName").html(data);
            });
        });
    </script>


    <style type="text/css">
        li{list-style: none; float: left;}
    </style>

</head>
<body>
<div class="container-fluid">

    <a id="userName" style="position: absolute; top: 20px; right: 20px;" href="#"></a>

    <div class="row-fluid">
        <div class="clo2">
            <div class="navbar">
                <div class="navbar-inner">
                    <ul class="nav">
                        <li class="active"><a href="/main.html">首页</a></li>
                        <li><a href="/addNode.html">写文章</a></li>
                        <li><a href="#">资讯</a></li>
                    </ul>
                </div>
            </div>
        </div>


        <div class="span10">

            <form class="form-horizontal" id="nodeForm" role="form" method="post" action="addNodeInfo">
                <div class="form-group">
                    <label for="firstname" class="col-sm-2 control-label">标题</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="nodeTitle"
                               placeholder="请输入标题">
                    </div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">正文</label>
                    <div class="col-sm-10">
                        <!--<textarea name="resume" id="nodeContent" style="width:1000px;height: 550px;" ></textarea>-->
                        <textarea id="content2" style="display:none;">...</textarea>
                        <div id="nodeContent"></div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <input  class="btn btn-info" onclick="subNode()" value="确认保存"/>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
</html>
